/**
 *
 */
var path = '../';
var pageListUrl = path + 'online/detail';
var pageUrl = path + 'online/';

// ---------------交互代码begin-----------------
$(function () {
    $(document).keyup(function (e) {
        if (e.which == 13) {
            $('#selectBtnEnter').click();
        }
    })
});

//绑定列表List---begin----所有的操作都围绕列表展开，新增、更新其他比较独立 
var dataList = new Vue({
    el: "#platformInfoList",
    data: {
        pageInfo: {},
        backPercent: "",
        //TODO 自定义条件查询---begin--------
        condition: {
            page: 1,
            platformType: 3,
            rows: customUtils.pageSize,
            status:"4",
            id: "",
            beginTime:"",
            endTime:"",
            shopName: "",
            startDate:"",
            overDate:"",
            equipmentCode: "",
            customerTotal:"",
            onlineTimeTotal: "",
            advCount: "",
        },
        selectedPageSize: customUtils.pageSize//修改页面数据显示条数
    },
    mounted: function () {
        //初始化页面数据
        this.getList('init');
    },
    // 在 `methods` 对象中定义方法,如果操作中函数的逻辑比较复杂，必须封装到dictType对象
    methods: {
        changeTime: function (elem) {
            dataList.$data.condition[elem.split('-')[0]] = $("#" + elem).val();
            console.log(dataList.$data.condition);
        },
        //搜索、分页列表
        getList: function (eventSrc) {
            var self = this;
            //改变页面显示条数
            if (eventSrc == "changePageSize") {
                if (this.pageInfo.pageSize != this.selectedPageSize) {
                    this.pageInfo.pageSize = this.selectedPageSize;
                    $('#pagination').jqPaginator('destroy');
                    eventSrc = 'init';//重新绘制控件
                } else {
                    return;
                }
            }
            //初始化时无当前页数，后台有默认第1页，每页10条
            if (this.pageInfo != undefined && this.pageInfo.pageNum != undefined) {
                self.condition["page"] = this.pageInfo.pageNum;
                self.condition["rows"] = this.pageInfo.pageSize;
            }
            var param = {};
            param["page"] = self.condition["page"];
            param["rows"] = self.condition["rows"];
            param["beginTime"] = self.condition["startDate"];
            param["endTime"] = self.condition["overDate"];
            param["status"] = self.condition["status"];
            param["equipmentCode"] = self.condition["equipmentCode"];
            this.condition.items = [];
            console.log(param)
            //查询请求
            //发送请求,第一个参数http对象，第二个是url，第三个是参数，第四个是成功回调，第五个是请求失败回调
            customUtils.post(self, pageListUrl, param, function (response, isSuccess) {
                //isSuccess代表此请求是否成功
                console.log(param);
                console.log(pageListUrl);
                if (isSuccess == false) {
                    dataList.pageInfo.pages = 0;
                    customUtils.noData('无数据', 0);
                    return;
                }
                dataList.pageInfo = response.body.pagination;
                customUtils.noData('无数据', dataList.pageInfo.pages);
                //页面初始化、搜索时，才需要执行分页控件
                if (eventSrc == 'init' || eventSrc == 'search') {
                    customUtils.paging('#pagination', dataList.pageInfo.pages, customUtils.showPage, function (num) {
                        //当前页码pageNum与将要翻页的页码num不相等才执行，否则为同一页
                        if (dataList.pageInfo.pageNum != num) {
                            dataList.pageInfo.pageNum = num;
                            dataList.getList('paging');
                        }
                    });
                }
            }, function (response) {
                console.log(response);
                dataList.pageInfo.pages = 0;
                customUtils.noData('无数据', 0);
            });
        },
        exportDetail: function () {
            var self = this;
            var  beginTime= self.condition["startDate"];
            var endTime=self.condition["overDate"];
            var equipmentCode = self.condition["equipmentCode"];
            var status = self.condition["status"];
            location.href = pageUrl + "exportDetail?beginTime=" + beginTime+"&endTime="+endTime+"&equipmentCode="+equipmentCode+"&status="+status;
        },
    }
});


